/*
 * main.c
 *
 *  Created on: 2014年2月27日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Time.h"
#include "Vector.h"
/**
 *@brief 测试Time类
 *
 */
int UseTimeClass()
{
	using std::cout;
	using std::endl;
	Time planning;
	Time coding(2, 40);
	Time fixing(5, 55);
	Time total;
	Time diff;
	Time adjusted;

	cout << "planning time = ";
	planning.Show();
	cout << endl;

	cout << "coding time = ";
	coding.Show();
	cout << endl;

	cout << "fixing time = ";
	fixing.Show();
	cout << endl;

	total = coding.Sum(fixing);
	cout << "total time = ";
	total.Show();
	cout << endl;

	total = coding + fixing;
	cout << "total time = ";
	total.Show();
	cout << endl;

	diff = fixing - coding;
	cout << "diff time = ";
	diff.Show();
	cout << endl;

	adjusted = coding * 1.5;
	cout << "adjusted time = ";
	adjusted.Show();
	cout << endl;

	adjusted = 1.5 * coding;
	cout << "use friend overwrite * symbol : time = ";
	adjusted.Show();
	cout << endl;

	cout << "use << overwrite 操作符:";
	cout << "支持多级级联" << adjusted << endl;

	return 0;
}
/**
 *@brief 展示对Vector类的使用.
 *功能:模拟随机行走(醉鬼行走)
 *功能:意思是喝醉酒后，行走的方向是随机的
 */
int UseVectorClass(void)
{
	using VECTOR::Vector;///使用命名空间声明
	using std::cout;
	using std::cin;
	using std::endl;
	srand(time(0));///产生随机种子数
	double direction;///方向
	Vector step;///行走的某一步
	Vector result(0.0,0.0);///行走后的目位置
	unsigned long steps=0;///总步数
	double target;///行走的目的距离
	double dstep;///步长

	cout<< "Enter target distance(q to quit): ";
	while(cin >> target){
		cout << "Enter step length: ";
		if(!(cin >> dstep))
			break;
		while(result.magval()<target){
			direction = rand()%360;///产生随机方向
			step.set(dstep,direction,'p');///表示走的步长和方向
			cout << "step:"<<dstep<<"direction:" << direction<<" cur step:"<<step<<endl;
			cout <<"-------divider line----- \n";
			///这里还调用了默认的赋值重载函数
			result = result+step;///更新位置,这里调用了加号成员重载函数
			steps++;///行走的总步数增加
		}
		cout << "After" << steps << "steps, the subject "
				"has the following location:\n";
		cout << result <<endl;///这里调用了：<<符号的友元重载函数

		result.poloar_mode();///改变输出模式
		cout << " or\n" << result<<endl;
		cout << "Average outward distance per step = "
			 << result.magval()/steps <<endl;
		steps =0;
		result.set(0.0,0.0);///注意这里只传了两个参数，最后一个参数使用默认值，见类声明处

		cout<< "Enter target distance(q to quit): ";///一轮模拟完成,是否开启另一次模拟
	}

	cout << "Bye !\n";

	return 0;
}

/**
 * 主函数入口
 */
int main()
{

//	UseTimeClass();
	UseVectorClass();



	return 0;
}


